const path = require('path')
const merge = require('webpack-merge')

module.exports = {
  mode: 'universal',
  /*
  ** Headers of the page
  */
  head: {
    title: process.env.npm_package_name || '',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: process.env.npm_package_description || '' },
	  { name: 'referrer', content: 'no-referrer' }	// 设置这个，就可以访问豆瓣防盗链图片
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },
  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },
  /*
  ** Global CSS
  */
  css: [
    'element-ui/lib/theme-chalk/index.css',
	'element-ui/lib/theme-chalk/reset.css',
	'assets/myTools/cssTools/index.styl',
	'assets/fontawesome/css/fontawesome.min.css',
  ],
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    '@/plugins/element-ui',
	// '@/plugins/global-components'	//引入全局组件
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
	// 关闭eslint
    // '@nuxtjs/eslint-module'
  ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
	'@nuxtjs/style-resources',	// 引入cssTools中mixins,color全局可用
	'nuxt-purgecss'	// 清除多余cssTools中的样式
  ],
  
  purgeCSS: {
	enabled:  false,	// 开启/关闭purgecss
	// whitelistPatterns: [/^van/]	//对vant的样式不做清除，在plugins里手动清除未引用组件。
  },
  
  styleResources: {
    stylus: [
      './assets/myTools/cssTools/global.styl'	//引入cssTools中的mixins, color，在组件中不用再import
    ]
  },
  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
  },
  /*
  ** Build configuration
  */
  build: {
    transpile: [/^element-ui/],
	cache: false,	// 开发模式，防止缓存，方便看到最新变化
	
    /*
    ** You can extend webpack config here
    */
    extend (config, ctx) {
		
		// 在组件里可以直接用这些名字开头
		config.resolve = merge(config.resolve, {
			alias: {
			  'components': path.resolve(__dirname, 'components'),
			  'assets': path.resolve(__dirname, 'assets'),
			  'pages': path.resolve(__dirname, 'pages'),
			  'http': path.resolve(__dirname, 'http'),
			  'utils': path.resolve(__dirname, 'utils'),
			  'store': path.resolve(__dirname, 'store')
			}
		})
		
		// 使用coffeescript配置
		config.module.rules.push({
			test: /\.coffee$/,
			use: ['coffee-loader']
		})
    }
  }
}
